/*
 * Copyright 2008-2023 dexian.vip. All rights reserved.
 * Support: http://www.dexian.vip
 * License: http://www.dexian.vip/license
 */

package vip.dexian.admin.command;

import vip.dexian.admin.enums.DataScopeEnum;
import vip.dexian.common.CommonAttributes;
import vip.dexian.core.base.command.BaseCommand;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.hibernate.validator.constraints.Length;

import java.io.Serial;
import java.util.List;

/**
 * 角色更新 表单数据
 *
 * @author 挺好的 2023年06月02日 08:45:40
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode (callSuper = false)
public class RoleUpdateCommand extends BaseCommand {

    @Serial
    private static final long serialVersionUID = -3342572397818998912L;

    /**
     * 标识
     */
    @NotEmpty (message = "角色标识不能为空")
    @Length (message = "角色标识长度应在2-30个字符之间", min = 2, max = 30)
    @Pattern (message = "用户名只允许数字、英文、下划线的组合", regexp = "^[0-9a-zA-Z_]+$")
    private String identity;

    /**
     * 名称
     */
    @NotEmpty (message = "角色名称不能为空")
    @Length (message = "角色名称的长度应在1-20个字符之间", min = 1, max = 20)
    private String name;

    /**
     * 描述
     */
    @Length (message = "角色描述信息长度不可超过200个字符", max = 200)
    private String description;

    /**
     * 系统内置。1：是，0：否
     */
    @NotNull (message = "请选择是否是系统内置")
    private Boolean isSystem;

    /**
     * 数据权限
     */
    @NotNull (message = "数据权限不能为空")
    private DataScopeEnum dataScope;

    /**
     * 关联部门ID
     */
    private List <Long> departmentIds;

    /**
     * 权限
     */
    @NotNull (message = "权限不能为空")
    private List <String> authorities;

    /**
     * 排序
     */
    @NotNull (message = "排序不能为空")
    @Min (value = 0, message = "排序不可小于0")
    @Max (value = 999_999_999, message = "排序不可大于999_999_999")
    private Integer order;

    /**
     * @return 角色标识
     */
    public String getFullIdentity () {
        return CommonAttributes.RoleSetting.ROLE_PREFIX + this.identity;
    }
}
